#include "Ro.h"

CRo::CRo(void)
{
}
CRo::CRo(LPDIRECT3DTEXTURE9 img, LPDIRECT3DDEVICE9 dev, int x, int y, int w, int h)
{
	this->img = img;
	this->result = D3DXCreateSprite(dev, &(this->handler));
	this->dev = dev;
	this->x = x;
	this->y = y;
	this->w = w;
	this->h = h;
	this->sprite.x = x;
	this->sprite.y = y;
	this->sprite.width = w;
	this->sprite.height = h;
}
void CRo::draw() {
	handler->Begin(D3DXSPRITE_ALPHABLEND);
	//create vector to update sprite position
	D3DXVECTOR3 position((float)this->sprite.x, (float)this->sprite.y, 0);
	//draw the sprite
	handler->Draw(
		this->img, 
		NULL,
		NULL,
		&position,
		D3DCOLOR_XRGB(255,255,255));
	//stop drawing
	handler->End();
}
void CRo::update(int val)
{
	if (this->sprite.x + val < 0 || this->sprite.x + val > 640 - this->sprite.width) {
		val = 0;
	}
	this->sprite.x += val;
}
SPRITE CRo::getSprite() {
	return this->sprite;
}
CRo::~CRo(void)
{
	img->Release();
	handler->Release();
}
